import {querySourceProblem,autoCompleteRoadName,getGroupMunicipalList,getGroupLandspaceList} from '@/services/config';

export default {
  nampspace: 'config',

  state: {
    sourceProblem: [],
    autoCompleteRoadNames: [],
    grouplist:[],
  },

  effects: {
    *fetchSourceProblem({ payload, callback }, { call, put }) {
      const response = yield call(querySourceProblem, payload);
      yield put({
        type: 'getSourceProblem',
        payload: response,
      });
    },
    
    *fetchAutoCompleteRoadName({ payload, callback }, { call, put }) {
      debugger
      const response = yield call(autoCompleteRoadName, payload);
      yield put({
        type: 'getRoadName',
        payload: response,
      });
      if (callback) callback(response);
    },

    *fetchGroupMunicipal({ payload, callback }, { call, put }) {
      const response = yield call(getGroupMunicipalList, payload);
      yield put({
        type: 'getGroup',
        payload: response,
      });
      if (callback) callback(response);
    },

    *fetchGroupLandspace({ payload, callback }, { call, put }) {
      const response = yield call(getGroupLandspaceList, payload);
      yield put({
        type: 'getGroup',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    getSourceProblem(state, action) {
      return {
        ...state,
        sourceProblem: action.payload,
      };
    },
    getRoadName(state, action) {
      return {
        ...state,
        autoCompleteRoadNames: action.payload,
      };
    },
    getGroup(state, action) {
      return {
        ...state,
        grouplist: action.payload,
      };
    },
  },
}